function  change_image(image_id,id,act_type)
{

	var value = 0;
	if($('#'+image_id).attr("src") == '/wondershare/images/yes.gif')
	{
		value = 0;
		$('#'+image_id).attr("src","/wondershare/images/no.gif"); 
	
	}else
	{
		value = 1;
		$('#'+image_id).attr("src","/wondershare/images/yes.gif");  
	}
	if(act_type == 'p_page_recommend' || act_type == 'p_page_delete' )
	{
		$.get("/wondershare/products_page.php?action=index", { in_jax: 1, page_id: id,type:act_type,value:value },
		function(data){
		
		});
	}else if(act_type == 'attributes_delete')
	{
	
		$.get("/wondershare/product_attributes.php?action=index", { in_jax: 1, attributes_id: id,type:act_type,value:value },
		function(data){
		
		});
	}
	else
	{
		$.get("/wondershare/products.php?action=index", { in_jax: 1, p_id: id,type:act_type,value:value },
		function(data){
		
		});
	}
}

function  check_info(id,check_tag,td_check_id,length,type)
{
	value = ($('#'+check_tag).html());
	value = value.replace(/"/g,'&quot;');
	$("#"+check_tag).remove();
	$("#"+td_check_id).html('<input type="text" id="input_'+check_tag+'"  value="'+value+'"   style="width:'+length+'px" />');
	$("#input_"+check_tag).focus();
	$("#input_"+check_tag).blur( function () 
	{ 					 
		var check_value = $('#input_'+check_tag).val();
		if(type == 'p_page_click' || type == 'p_chang_count' || type == 'p_sort' || type == 'page_sort')
		{
			check_value = parseInt(check_value);
		}
		var str ="<span   id='"+check_tag+"' >"+check_value+"</span>";
		$("#"+td_check_id).html("");
		$("#"+td_check_id).html(str);

		$("#"+check_tag).mouseout( function () { check_css(check_tag,0); }); 
		$("#"+check_tag).mouseover( function () { check_css(check_tag,1); }); 

		$("#"+check_tag).click( function () { check_info(id,check_tag,td_check_id,length,type); }); 
		
		if(type == 'p_sort')
		{
			
			$.get("/wondershare/products.php?action=index", { in_jax: 1, p_id: id,value:check_value,type:type },
			function(data){});  
		}else if(type == 'title' || type == 'pic_min' || type == 'pic_max')
		{
			$.get("/wondershare/feature.php?action=index", { in_jax: 1, feature_id: id,value:check_value,type:type },
			function(data){});   
		}
		else if(type == 'page_sort' )
		{
		
			$.get("/wondershare/products_page.php?action=index", { in_jax: 1, page_id: id,value:check_value,type:type },
			function(data){});   
		}else if(type == 'attributes_name')
		{
		
			$.get("/wondershare/product_attributes.php?action=index", { in_jax: 1, attributes_id: id,value:check_value,type:type },
			function(data){});   
		}
		else if(type == 'product_sort')//在store里面的产品排序
		{
		
			var store_id = $("#store_id").val();
			$.get("/wondershare/store.php?action=UpdateStore", { store_id: store_id, product_id: id,value:check_value,type:type },
			function(data){});   
		}


	});


}


function  check_css(sort_tag,type)
{
	if(type==1)
	{
		$("#"+sort_tag).css({  "background": "blue","color": "#ff0011"}); 
	}
	else
	{
		$("#"+sort_tag).css({ "background": "","color":""}); 
	}

}


function tab()
{
	$('#tab_info').find("span").mouseover(function()
	{
		$('#tab_info').find("span").removeClass("tab-front");
		$('#tab_info').find("span").addClass("tab-back");
		$(this).removeClass("tab-back");
		$(this).addClass("tab-front");
		var target = $('#' + this.id+'le');
		if (target.size() > 0) 
		{
			$('#tabbody-div').find("table").hide();
			target.show();
		} 
	});
	select_checkbox('attributes','w_attributes_str');
}
function in_array(needle, haystack) 
{

	var type = typeof needle;
	if(type == 'string' || type =='number') 
	{
		for(var i in haystack) 
		{
			if(haystack[i] == needle) 
			{
				return true;
			}
		}
	}
	return false;
}

function  select_checkbox(name,select_id)
{
	var str_attr = '';
	var strs = new Array(); //定义一数组
	str_attr = $("#"+select_id).val();
	strs = str_attr.split(",");
	for (i=0;i<strs.length ;i++ )    
	{
	
		$('input[name="'+name+'[]"]').each(function () {
			if($(this).val() == strs[i] )
			{
				$(this).attr('checked',true);
			} });
		}
	
}

function create_FCKedito(value)
{

	var oFCKeditor          = new FCKeditor(value);      //创建FCK对象
	oFCKeditor.Height      = 400;        //设置FCK显示高度
	oFCKeditor.Width      = 850;        //设置FCK显示宽度
	oFCKeditor.BasePath   = "../../fckeditor/";    //指定编辑器路径，要加载fckeditor/editor/fckeditor.html
	oFCKeditor.ReplaceTextarea(); 
}

function create()
{

	tab();
}
function  create_bar_div(str2)
{
	$("#page_bar_A2_"+str2).click(function() 
	{
		select_checkbox('bar','page_bar_'+str2);
		$(".A1Demo"+str2).remove();
		$('.A4Demol0').after('<div class="A1Demo'+str2+'" style="display: none; width: 550px; padding: 10px;"  id="A1Demo'+str2+'">'+
		'<div id="pageDemo'+str2+'">'+$('#info').html()+'<br /><input type="button"    value="确定" name="check_pagebar_'+str2+'"  '+
		'id="check_pagebar_'+str2+'"  style="margin-top:20px; margin-left:200px;"></div></div>');
		$('#check_pagebar_'+str2).click( function () { select_bar("page_bar_"+str2,'pageDemo'+str2); });
		$(".A1Demo"+str2).cvbox(
		{
			titleBarText: "选择页面右侧块"
		});
		$('pageDemo'+str2).show();
		
	}); 
}

function  select_attributes(id)
{
	var str_attr = '';
	var str = "";
	var str_name = "";
	var original_strs = new Array(); //定义一数
	var attributes_strs = new Array(); //定义一数组
	str_attr = $("#w_attributes_str").val();
	original_strs = str_attr.split(",");

///$("table[id*='attributes']").remove();  
//$("span[id*='attributes']").remove();  
	$('input[name="attributes[]"]').each(function () {
		if ($(this).attr('checked')) 
		{
			str += $(this).val() + ",";
			str_name +=$(this).attr('title') + ",";
			if(!in_array($(this).val(),original_strs))
			{
			
				$('#submit_div').before('<table width="90%" style="display:none" id="attributes'+$(this).val()
				+'-table"><tbody> <tr><td>页面标题</td>'+
				'<td><input type="text" size="70"   name="page_title'+$(this).val()
				+'" ></td></tr><tr><td>页面内容</td><td><textarea name="page_content'+
				$(this).val()+'" size="50"  />   </textarea></td></tr></tbody>'+
				'</table>'); 
				create_FCKedito('page_content'+$(this).val());
				$('#tab_info').append('<span id="attributes'+$(this).val()+'-tab" class="tab-back">'+$(this).attr('title')+'</span>');
				var  str2 = $(this).val();
				create_bar_div(str2);
			}
		}
	});
	attributes_strs = str.split(",");
	$.each(original_strs, function(key, value)
	{ 
		if(!in_array(value,attributes_strs))
		{
			$('#attributes'+value+'-table').remove();  
			$('#attributes'+value+'-tab').remove();
		}
	})

	$("#w_attributes_id").val(str_name);
	$("#w_attributes_str").val(str);
	tab(); 
	$("#cvBoxTitleBarClose").click();
	$('#'+id).hide();
}


function delete_repeat(str)
{
	var string_arr = str.split(",");//分割字符串
	var arr = [],map = {},i,n;
	for(i=0; i<string_arr.length; i++)
	{
		n = string_arr[i];
		if(!map.hasOwnProperty(n))
		{ //去掉数组中重复的元素
		map[n] = true;
		arr.push(n);
		}
	} 
	str = arr.join(",");
	return  str;
}

function  select_bar(id,type_id)
{
	var str = "";
	var str_name = "";
	$('input[name="bar[]"]').each(function () {
		if ($(this).attr('checked')) 
		{
		str += $(this).val() + ",";
		str_name +=$(this).attr('title') + ',';
		}

	});
	$("#"+id).val(delete_repeat(str_name));
	$("#"+id+'_str').val(delete_repeat(str));
	$("#cvBoxTitleBarClose").click( );
	$("#"+type_id).hide();
}


function  delete_info(id,tr_id,act_type)
{

	if(act_type == 'del')
	{
		$.get("/wondershare/products.php?action=index", { in_jax: 1,p_id:id, type: act_type ,value:1},
		function(data){
		if(data == 1)
		{
			$("#"+tr_id).remove();
			$('#total').html(parseInt($('#total').html())-1) ;
		}else
		{
		alert('删除失败!');
		}
		});
	}
	else if(act_type == 'p_page_delete')  
	{
		$.get("/wondershare/products_page.php?action=index", { in_jax: 1,page_id:id, type: act_type ,value:1},
		function(data){
		
		if(data == 1)
		{
			$("#"+tr_id).remove();
			$('#total').html(parseInt($('#total').html())-1) ;
		}else
		{
			alert('删除失败!');
		}
		});
	}
	else if(act_type == 'attributes_delete')  
	{
		$.get("/wondershare/product_attributes.php?action=index", { in_jax: 1,attributes_id:id, type: act_type ,value:1},
		function(data){
		
			if(data == 1)
			{
				$("#"+tr_id).remove();
				$('#total').html(parseInt($('#total').html())-1) ;
			}else
			{
			alert('删除失败!');
			}
		});
	}

}


function getproductlist(type){
	var products_id = $("#products_id").val();
	var web_type = $("#web_type").val();
	var web_info = $("#web_info").val();
	if(type == 'products_id')
	{
		var product_list = $("#hidden_products_id").val();
		jIframe('', '所有公共产品列表', {
		width: 750,
		height: 345,
		src: './product.php?action=RecommProductTwo&product_list='+product_list+'&web_type='+web_type,
		ID: 'all_product',
		box_btn:true,
		callback:add_okbtn
		});
	}else if(type == 'recommended_product')
	{
		var product_list = $("#h_recommended_product").val();
		jIframe('', '所有'+web_info+'产品列表', {
		width: 850,
		height: 345,
		src: './products.php?action=index&type=1&product_list='+product_list+'&products_id='+products_id+'&web_type='+web_type,
		ID: 'all_product',
		box_btn:true,
		callback:add_okbtn_tow
		});
	}
	else if(type == 'high_product')
	{
		var product_list = $("#h_high_product").val();
		
		jIframe('', '所有'+web_info+'产品列表', {
		width: 850,
		height: 345,
		src: './products.php?action=index&type=2&product_list='+product_list+'&products_id='+products_id+'&web_type='+web_type,
		ID: 'all_product',
		box_btn:true,
		callback:add_okbtn_three
		});
	}

}
function add_okbtn()
{
	var web_type = $('#web_type').val();
	var id = document.getElementById("all_product").contentWindow.get_checked_product();
	var name = document.getElementById("all_product").contentWindow.get_checked_product_name();

	$("#hidden_products_id").val(id);
	var fage = 0;
	jClose();
	$.ajax({
	type: "GET",
	url: "/wondershare/products.php?action=index",
	async: false,
	data:"in_jax=2&p_id="+$('#hidden_products_id').val()+"&web_type="+web_type,
	success: function(data)
	{
		if(data == 1)
		{
			alert('你要增加的产品已经存在库中，请重新选择！');
			$("#products_id").val('');
			$('#hidden_products_id').val('');
			fage = 1;
		}
	}
	});
	if(fage == 0)
	{
		$("#products_id").val(name);
	}else
	{
		$("#products_id").val('');
	}
}

function add_okbtn_tow()
{
	var id = document.getElementById("all_product").contentWindow.get_checked_product();
	var name = document.getElementById("all_product").contentWindow.get_checked_product_name();
	$("#recommended_product").val(name);
	$("#h_recommended_product").val(id);
	jClose();
}

function add_okbtn_three()
{
	var id = document.getElementById("all_product").contentWindow.get_checked_product();
	var name = document.getElementById("all_product").contentWindow.get_checked_product_name();
	if (typeof(name) == "undefined") 
	{ 
		$("#high_product").val('');
	}else
	{
		$("#high_product").val(name); 
	}
	
	if (typeof(id) == "undefined") 
	{ 
		$("#h_high_product").val('');
	}else
	{
		$("#h_high_product").val(id); 
	}


//alert(name);

	jClose();
}

function  delete_product(ar_id,type,act_type)
{

	var str = "";
	var tips = '确定删除记录吗?';
	var falge = false;
	
	$('input[name="ID[]"]').each(function () {
	if ($(this).attr('checked')) 
	{
		falge = true; 
		str += $(this).val() + ",";
	}
	});
	
	
	if(!falge)
	{ 
		alert('你没有选择任何选项！');  
		return false;
	}
	
	if(confirm(tips))
	{ 
		if(act_type == 'del_products')
		{
			$.get("/wondershare/products.php?action=index", { in_jax: 2, checkList: str ,type:'del_products'},
			function(data){
			
			});  
		}
		$('input[name="ID[]"]').each(function () {
			if ($(this).attr('checked')) 
			{
			$("#tr_"+$(this).val()).remove();
			$('#total').html(parseInt($('#total').html())-1) ;
			}
		}); 
	
	
	}
}











